/*  * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
onload = function(){
	dropZone();
}

function dropZone(){
    var dropbox;
    dropbox = document.getElementById("dropbox");
    dropbox.addEventListener("dragenter", dragenter, false);
    dropbox.addEventListener("dragover", dragover, false);
    dropbox.addEventListener("drop", drop, false);

    function dragenter(e) {
        e.stopPropagation();
        e.preventDefault();
    }
    function dragover(e) {
        e.stopPropagation();
        e.preventDefault();
    }

    function drop(e) {
        e.stopPropagation();
        e.preventDefault();
        var dt = e.dataTransfer;
        var files = dt.files;
        handleFiles(files);
    }

    function handleFiles(files){
    	alert("in");
    	fileUpload(files[0]);
    }
    
    function fileUpload(file) {

  		var reader = new FileReader();
  		var xmlhttp = new XMLHttpRequest();
  		xmlhttp.open("POST","./HadoopStorageControll?fileName="+file.fileName,true);
  		xmlhttp.overrideMimeType("image/jpeg");
  		reader.onload = function(evt){
  			alert(evt.target.result);
  			xmlhttp.send(evt.target.result);
  		}
  		xmlhttp.onreadystatechange = function(){
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
  				alert(xmlhttp.responseText);
  			}
  		}
  		reader.readAsDataURL(file);
    }
}